<ol class="breadcrumb">
    <li><a href="#">一元中奖</a></li>
    <li>申请管理</li>
</ol>
<div class="panel panel-default">
    <div class="panel-heading">
        <span class="icon-gift icon-large"></span>
        <span class="panel-title">申请列表</span>
    </div>
    <div class="panel-body">
        <% if(session.permissionMap[3006]){ %>
        <a href="#" onclick="rejected()" class="btn btn-danger btn-sm">驳回</a>
        <% } %>
        <% if(session.permissionMap[3007]){ %>
        <a href="#" onclick="pass()" class="btn btn-success btn-sm">通过</a>
        <% } %>
        <% if(session.permissionMap[9999999999999]){ %>
        <a href="#" onclick="getCheckIds()" class="btn btn-default btn-sm">商品上架</a>
        <% } %>
    </div>
    <div class="table-responsive">
        <table class="table table-hover table-striped" id="applyforTable">
            <thead>
            <tr>
                <th>√</th>
                <th style="width:80px;">商品名称</th>
                <th>链接地址</th>
                <th style="width:250px">申请时间</th>
                <th style="width:80px;">审核状态</th>
            </tr>
            </thead>
            <tfoot>
            <tr>
                <td colspan="11">
                    <nav class="twbsPagination"></nav>
                </td>
            </tr>
            </tfoot>
            <tbody>
            <% data.rows.forEach(function(applyfor, index){ %>
            <tr>
                <th><input name="applyfor_id" type="checkbox" value="<%= applyfor.id %>"></th>
                <td><%= applyfor.name %></td>
                <td><%= applyfor.url %></td>
                <td><%= applyfor.createtime %></td>
                <td>
                    <% if(applyfor.status == 'no'){ %>
                    未通过
                    <% }else if(applyfor.status == 'yes'){ %>
                    已通过
                    <% }else{ %>
                    未审核
                    <% } %>
                </td>

            </tr>
            <% }) %>

            </tbody>
        </table>
    </div>
</div>
<style>
    .thumb {
        width: 30%;
        /*background-image: url("http://123.57.72.99:3000/images/goods/5881b28b2f6e8730d409a251e83c9a0f.jpg");*/
        background-repeat: no-repeat;
        background-size: cover;
        height: 80px;
        width: 80px;
        margin: 3px;
    }
</style>

<script>
    init(<%= data.total%>);//初始化分页
    function init(total) {
        //分页功能
        $('.twbsPagination').twbsPagination({
            totalPages: parseInt((Number(total) + 10 - 1) / 10, 10),
            visiblePages: 10,
            onPageClick: function (event, page) {
                reloadpage(page, false);
            }
        });
    }
    function reloadpage(page, isinit) {
        $.get("/applyfor/list",
                {page: page},
                function (result) {
                    if (isinit) {
                        init(result.total);
                    }

                    if (result.rows.length < 1) {
                        $('#rowcontent').html('无数据...');
                        return;
                    }
                    var html = '';
                    result.rows.forEach(function (applyfor, index) {
                        var status = '未审核';
                        if (applyfor.status == 'no') {
                            status = '未通过';
                        } else if (applyfor.status == 'yes') {
                            status = '已通过';
                        }
                        html += '<tr><td><input name="applyfor_id" type="checkbox" value="' + applyfor.id + '"></td>' +
                                '<td>' + applyfor.name + '</td>' +
                                '<td>' + applyfor.url + '</td> <td>' + applyfor.createtime + '</td><td>' + status + '</td></tr>';
                    });
                    $('#applyforTable tbody').html(html);
                });
    }


    function getCheckIds() {
        var adIds = "";
        $("input:checkbox[name='applyfor_id']:checked").each(function (i) {
            if (0 == i) {
                adIds = $(this).val();
            }
        });
        if (!adIds) {
            return alert('请选择一条记录!');
        }
        window.location.href = "/goods/add?id=" + adIds;
    }
    function getCheckIds1() {
        var adIds = "";
        $("input:checkbox[name='applyfor_id']:checked").each(function (i) {
            if (0 == i) {
                adIds = $(this).val();
            } else {
                adIds += ("," + $(this).val());
            }
//            alert(adIds);
        });

    }

    function rejected() {
        var id = selectid();
        if (!id) {
            return alert('请选择一条记录!');
        }
        $.post('/applyfor/update', {id: id, status: 'no'}, function (result) {
            if (result.msg) {
                location.reload(true);
            } else {
                alert('失败！');
            }
        });
    }
    function pass() {
        var id = selectid();
        if (!id) {
            return alert('请选择一条记录!');
        }
        $.post('/applyfor/update', {id: id, status: 'yes'}, function (result) {
            if (result.msg) {
                location.reload(true);
            } else {
                alert('失败！');
            }
        });
    }
    function selectid() {
        var adIds = "";
        $("input:checkbox[name='applyfor_id']:checked").each(function (i) {
            if (0 == i) {
                adIds = $(this).val();

            }
        });
        if (!adIds) {
            return alert('请选择一条记录!');
        }
        return adIds;
    }
</script>